<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <title>地图展示</title>
        <meta name="description" content="地图展示">
        <meta name="keywords" content="地图展示">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=7oj6qP0pgHF16AMtVR5Fj0hz9pjQFlhv"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
            body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
            #l-map{height:500px;width:100%;}
            #r-result{width:100%; font-size:14px;line-height:20px;}
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">

            <!-- 新增标签弹层 -->
            <div class="add-form" >
                <el-dialog title="新增地址" :visible.sync="dialogFormVisible" style="height: 700px">
                    <el-container>
                        <iframe name="right" class="el-main" src="hint.html" width="100%" height="500px" frameborder="0"></iframe>
                    </el-container>
                </el-dialog>
            </div>

            <div class="content-header">
                <h1>首页<small>公司分布图</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div>
                        <template>
                            <el-tabs v-model="activeName" @tab-click="handleClick">
                                <el-tab-pane label="分布图" name="first">
                                    <el-container>
                                        <iframe name="right" class="el-main" src="addr.html" width="100%" height="700px" frameborder="0"></iframe>
                                    </el-container>
                                </el-tab-pane>

                                <el-tab-pane label="详细信息" name="second">
                                    <div class="filter-container">
                                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                                        <el-button @click="findMatch()" class="dalfBut">查询</el-button>
                                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                                    </div>
                                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                                        <el-table-column prop="addressname" label="公司地址" align="center"></el-table-column>
                                        <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                                        <el-table-column prop="latitude" label="所在维度" align="center"></el-table-column>
                                        <el-table-column label="操作" align="center">
                                            <template slot-scope="scope">
                                                <el-button size="mini" type="danger" @click="handledelete(scope.row)">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                    <div class="pagination-container">
                                        <el-pagination
                                                class="pagiantion"
                                                @current-change="handleCurrentChange"
                                                :current-page="pagination.currentPage"
                                                :page-size="pagination.pageSize"
                                                layout="total, prev, pager, next, jumper"
                                                :total="pagination.total">
                                        </el-pagination>
                                    </div>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:8,
                    total:100,
                    queryString:null,
                },
                dataList: [],//列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//控制添加窗口显示/隐藏
            },
            created() {
                this.findPage();
            },
            methods: {
                findMatch(){
                    this.pagination.currentPage=1;
                    this.findPage();
                },
                //分页查询
                findPage() {
                    var params={
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString,
                    };
                    axios.post("/address/findPage.do",params).then((response)=>{
                        this.pagination.total=response.data.total;
                        this.dataList=response.data.rows;
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData={};
                },
                // 弹出添加窗口
                handleCreate() {
                    this.dialogFormVisible=true;
                    this.resetForm();
                    axios.get("/address/findAllAddress.do").then((response)=>{
                        if (response.data.flag){
                            this.tableData=response.data.data;
                        }else {
                            this.$message.error(response.data.message);
                        }
                    });
                },
                closehandleCreate(){
                    this.dialogFormVisible=false;
                    this.findPage();
                    this.$message.success("地址添加成功");

                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage=currentPage;
                    this.findPage();

                },
                handleCloseDia(){
                    this.dialogFormVisible=false;
                    this.$message.success("添加成功!");
                    this.findPage();
                },
                //执行删除操作
                handledelete(row){
                    this.$confirm("确认要删除吗？","提示",{type: 'warning'}).then(()=>{
                        axios.post("/address/deleteAddress.do?id="+row.id).then((response)=>{

                            //存在删除当页全部数据后查询为空的bug
                            if(response.data.flag){
                                this.findPage();
                                this.$message.success(response.data.message);
                            }else {
                                this.$message.error(response.data.message);
                            }
                        });
                    }).catch(()=>{
                        this.$message.info("已取消删除");
                    });
                }
            }
        })
    </script>
</html>
